﻿using Vboot.Core.Module.Ass;

namespace Vboot.Core.Framework;

//辅助数据初始化
public class AssInit : ITransient
{
    private readonly SqlSugarRepository<AssNumMain> _numRepo;

    private readonly SqlSugarRepository<AssDictMain> _dictMainRepo;

    private readonly SqlSugarRepository<AssDictData> _dictDataRepo;

    public AssInit(SqlSugarRepository<AssNumMain> numRepo,
        SqlSugarRepository<AssDictMain> dictMainRepo,
        SqlSugarRepository<AssDictData> dictDataRepo)
    {
        _numRepo = numRepo;
        _dictMainRepo = dictMainRepo;
        _dictDataRepo = dictDataRepo;
    }

    public async Task InitData()
    {
        await InitNum();
        await InitDict();
    }

    //流水号初始化
    private async Task InitNum()
    {
        List<AssNumMain> numList = new List<AssNumMain>();
        AssNumMain suppNum = new AssNumMain();
        suppNum.id = "SUPP";
        suppNum.name = "供应商流水号";
        suppNum.numod = "yyyymmdd";
        suppNum.nulen = 3;
        suppNum.nflag = true;
        suppNum.nupre = "SU";
        numList.Add(suppNum);

        AssNumMain projNum = new AssNumMain();
        projNum.id = "PROJ";
        projNum.name = "项目流水号";
        projNum.numod = "yyyymmdd";
        projNum.nulen = 3;
        projNum.nflag = true;
        projNum.nupre = "PR";
        numList.Add(projNum);

        AssNumMain custNum = new AssNumMain();
        custNum.id = "CUST";
        custNum.name = "客户流水号";
        custNum.numod = "yyyymmdd";
        custNum.nulen = 3;
        custNum.nflag = true;
        custNum.nupre = "CU";
        numList.Add(custNum);

        AssNumMain agentNum = new AssNumMain();
        agentNum.id = "AGENT";
        agentNum.name = "代理商流水号";
        agentNum.numod = "yyyymmdd";
        agentNum.nulen = 3;
        agentNum.nflag = true;
        agentNum.nupre = "AG";
        numList.Add(agentNum);
        await _numRepo.InsertRangeAsync(numList);
    }

    //数据字典初始化
    private async Task InitDict()
    {
        List<AssDictMain> dictList = new List<AssDictMain>();

        AssDictMain suppDict = new AssDictMain();
        suppDict.id = "SU_LEVEL";
        suppDict.name = "供应商资质等级";
        suppDict.avtag = true;
        dictList.Add(suppDict);

        AssDictMain agentDict = new AssDictMain();
        agentDict.id = "AG_LEVEL";
        agentDict.name = "代理商资质等级";
        agentDict.avtag = true;
        dictList.Add(agentDict);

        await _dictMainRepo.InsertRangeAsync(dictList);

        List<AssDictData> dictDataList = new List<AssDictData>();
        AssDictData supp1 = new AssDictData();
        supp1.id = YitIdHelper.NextId() + "";
        supp1.code = "A";
        supp1.name = "A级资质";
        supp1.avtag = true;
        supp1.ornum = 1;
        supp1.maiid = "SU_LEVEL";
        dictDataList.Add(supp1);

        AssDictData supp2 = new AssDictData();
        supp2.id = YitIdHelper.NextId() + "";
        supp2.code = "B";
        supp2.name = "B级资质";
        supp2.avtag = true;
        supp2.ornum = 2;
        supp2.maiid = "SU_LEVEL";
        dictDataList.Add(supp2);

        AssDictData supp3 = new AssDictData();
        supp3.id = YitIdHelper.NextId() + "";
        supp3.code = "C";
        supp3.name = "C级资质";
        supp3.avtag = true;
        supp3.ornum = 3;
        supp3.maiid = "SU_LEVEL";
        dictDataList.Add(supp3);

        AssDictData supp4 = new AssDictData();
        supp4.id = YitIdHelper.NextId() + "";
        supp4.code = "Z";
        supp4.name = "不合格";
        supp4.avtag = true;
        supp4.ornum = 4;
        supp4.maiid = "SU_LEVEL";
        dictDataList.Add(supp4);

        AssDictData agent1 = new AssDictData();
        agent1.id = YitIdHelper.NextId() + "";
        agent1.code = "A";
        agent1.name = "A级资质";
        agent1.avtag = true;
        agent1.ornum = 1;
        agent1.maiid = "AG_LEVEL";
        dictDataList.Add(agent1);

        AssDictData agent2 = new AssDictData();
        agent2.id = YitIdHelper.NextId() + "";
        agent2.code = "B";
        agent2.name = "B级资质";
        agent2.avtag = true;
        agent2.ornum = 2;
        agent2.maiid = "AG_LEVEL";
        dictDataList.Add(agent2);

        AssDictData agent3 = new AssDictData();
        agent3.id = YitIdHelper.NextId() + "";
        agent3.code = "C";
        agent3.name = "C级资质";
        agent3.avtag = true;
        agent3.ornum = 3;
        agent3.maiid = "AG_LEVEL";
        dictDataList.Add(agent3);

        AssDictData agent4 = new AssDictData();
        agent4.id = YitIdHelper.NextId() + "";
        agent4.code = "Z";
        agent4.name = "不合格";
        agent4.avtag = true;
        agent4.ornum = 4;
        agent4.maiid = "AG_LEVEL";
        dictDataList.Add(agent4);

        await _dictDataRepo.InsertRangeAsync(dictDataList);
    }
}